﻿using System;
using System.IO;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;

using SBPweb.PROvibe.Server.Framework.Contracts;
using SBPweb.PROvibe.Server.Framework.Contracts.Parameters;

using SBPweb.PROvibe.Server.Framework.Utilities.Collections;

namespace SBPweb.PROvibe.Server.Framework.Actors.Parameters
{

    public class EntryInitializationParametersDictionary : OverridableDictionary<string, IEntryInitializationParameter>, IEntryInitializationParametersDictionary
    {

        public EntryInitializationParametersDictionary()
            : base()
        {
        }

        public static string Serialize(IEntryInitializationParametersDictionary dictionary)
        {
            string ret = string.Empty;
            foreach (KeyValuePair<string, IEntryInitializationParameter> kvp in dictionary)
            {
                ret += string.Format("{0}={1},", kvp.Key, Encrypt(EntryInitializationParameter.Serialize(kvp.Value)));
            }
            return ret;
        }

        private static string Encrypt(string stuff)
        {
            //Aes aes = new AesManaged();
            //aes.Key = Encoding.UTF8.GetBytes("SBPweb.PROvibe.S");
            //ICryptoTransform ict = aes.CreateEncryptor();
            //byte[] bytesIn = Encoding.Unicode.GetBytes(stuff);
            //byte[] bytesOut = (byte[])Array.CreateInstance(typeof(byte), bytesIn.Length);
            //ict.TransformBlock(bytesIn, 0, aes.BlockSize, bytesOut, 0);
            //return HttpUtility.UrlEncode(Encoding.Unicode.GetString(bytesOut));
            return stuff;
        }


        //public static EntryInitializationParametersDictionary Deserialize(IDictionary<string, string> itemParams)
        //{
        //    EntryInitializationParametersDictionary ret = new EntryInitializationParametersDictionary();
        //    foreach (KeyValuePair<string, string> kvp in itemParams)
        //    {
        //        EntryInitializationParameter eip = EntryInitializationParameter.Deserialize(kvp.Value);
        //        ret.Add(kvp.Key, eip);
        //    }
        //    return ret;
        //}

    }

}